/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.runtime;

import org.proteusframework.api.base.AbstractRuntimeConfiguration;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Provides a default runtime implementation of the Proteus Framework. Most applications can simply rely on the default
 * runtime configuration.
 *
 * @author Tacoma Four
 */
public class DefaultRuntimeConfiguration extends AbstractRuntimeConfiguration
{
    private static final Logger logger = Logger.getLogger(DefaultRuntimeConfiguration.class.getCanonicalName());

    @Override
    protected void onDelegateInjected()
    {
        if (logger.isLoggable(Level.FINEST))
            logger.finest("Delegate injected into DefaultRuntimeConfiguration");


        // Locate the proteus.properties file on the CLASSPATH and read its values into the

        if (logger.isLoggable(Level.FINEST))
            logger.finest("Attempting to load /proteus.properties from the CLASSPATH");

        InputStream inputStream = getClass().getResourceAsStream("/proteus.properties");

        if (null == inputStream)
        {
            logger.severe("Unable to locate /proteus.properties on the CLASSPATH");
        } else
        {
            try
            {
                Properties p = new Properties();
                p.load(inputStream);


                if (logger.isLoggable(Level.FINE))
                    logger.fine("Located a total of " + p.size() + " configuration properties in /proteus.properties");

                //
                // TODO: Process the .properties file from the input stream

            } catch (IOException e)
            {
                logger.severe("Exception reading /proteus.properties from the CLASSPATH: " + e.getMessage());
            }

        }
    }
}
